package com.yc.cloud.mapper;

import com.yc.cloud.entity.UmsResource;
import com.yc.cloud.entity.UmsRoleResourceRelation;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 后台角色资源关系表 Mapper 接口
 * </p>
 *
 * @author JackGu
 * @since 2022-09-11
 */
@Mapper
public interface UmsRoleResourceRelationMapper extends BaseMapper<UmsRoleResourceRelation> {

    @Select(" SELECT\n" +
            "            r.id id,\n" +
            "            r.create_time createTime,\n" +
            "            r.`name` `name`,\n" +
            "            r.url url,\n" +
            "            r.description description,\n" +
            "            r.category_id categoryId\n" +
            "        FROM\n" +
            "            ums_role_resource_relation rrr\n" +
            "                LEFT JOIN ums_resource r ON rrr.resource_id = r.id\n" +
            "        WHERE\n" +
            "            rrr.role_id = #{roleId}\n" +
            "          AND r.id IS NOT NULL\n" +
            "        GROUP BY\n" +
            "            r.id")
    List<UmsResource> queryByRoleId(@Param("roleId") Long roleId);
}
